import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import com.feng.util.DateUtil;


public class Main {
	Timer waitTimer = new Timer("Test-Timer", true); 
	private int syncContactListCount = 0;
	private int count;
	TimerTask task;
	String st = null;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		Main.p(1351925468812L);//t
		//System.out.println(count);
		new Main().test1();
		while(true){
		}
	}

	private static void p(long date) {
		System.out.println(DateUtil.formatDate2String(new Date(date),DateUtil.YYYY_MM_DD_HHMMSS));
	}
	
	private void test2(){
		System.out.println("test2()-1:"+count++);
		System.out.println("syncContactListCount:"+syncContactListCount);
		if(st != null){
			System.out.println("内容为空");
		}else if(syncContactListCount++ >= 3){
			System.out.println("test2()-2:"+count++);
    		task.cancel();
        	task=null;
        	syncContactListCount = 0;
    	}
	}
	
	private void test1(){
		System.out.println("test1()-1:"+count++);
		task =new TimerTask() {
			public void run() {
				System.out.println("test1()-2:"+count++);
            	try{
            		test2();
            		System.out.println("test1()-3:"+count++);
            	}catch(Exception e){
            		System.out.println(e);
            	}
            	System.out.println("test1()-4:"+count++ +" Retry "+syncContactListCount+" times.");
             }
        };
        System.out.println("test1()-5:"+count++);
		waitTimer.schedule(task, 0, 6000);
		
		System.out.println("test1()-6:"+count++);
	}
}
